package com.scau.clothes.stock.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.scau.clothes.stock.mapper.ClothesMapper;
import com.scau.clothes.stock.model.dto.ClothesDto;
import com.scau.clothes.stock.model.entity.Clothes;
import com.scau.clothes.stock.service.ClothesService;
import jakarta.annotation.Resource;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@AllArgsConstructor
public class ClothesServiceImpl extends ServiceImpl<ClothesMapper, Clothes> implements ClothesService {

    @Resource
    private ClothesMapper clothesMapper;

    @Override
    public int insertClothes(Clothes clothes) {
        clothes.setIsDelete(0);
        return clothesMapper.insert(clothes);
    }

    @Override
    public int updateClothes(Clothes clothes) {
        return clothesMapper.updateById(clothes);
    }

    @Override
    public int deleteClothes(Clothes clothes) {
        clothes.setIsDelete(1);
        return clothesMapper.updateById(clothes);
    }

    @Override
    public List<Clothes> listClothes(ClothesDto clothesDto) {
        List<Clothes> list = clothesMapper.listAllClothes(clothesDto);
        return list;
    }

    @Override
    public Clothes selectClothesByClothesNumber(String clothesNumber) {
        QueryWrapper<Clothes> queryWrapper = new QueryWrapper<>();
        if (StrUtil.isNotBlank(clothesNumber))
            queryWrapper.eq("clothes_number", clothesNumber);
        Clothes clothes = clothesMapper.selectOne(queryWrapper);
        return clothes;
    }
}
